// Copyright (c) 1996-2002 John Lyon-Smith. All rights reserved.

#pragma once

#include <wxtl\SyncObject.h>

namespace wxtl
{
	class Event : public SyncObject
	{
	public:
		Event() throw()
		{
		}
		Event(Event &event) throw() :
			SyncObject(event)
		{
		}
		explicit Event(HANDLE hEvent) throw() :
			SyncObject(hEvent)
		{
		}
		~Event()
		{
		}
		Event& operator=(Event& h) throw()
		{
			return (Event&)Handle::operator=(h);
		}

		bool create(
			bool bManualReset = false, 
			bool bInitialState = false, 
			const TCHAR* pszName = NULL, 
			LPSECURITY_ATTRIBUTES psa = NULL)
		{
			_ASSERTE(!isValid());
			return ((m_h = ::CreateEvent(psa, bManualReset, bInitialState, pszName)) != NULL);
		}
		bool open(const TCHAR* pszName = NULL, DWORD dwAccess = EVENT_ALL_ACCESS, bool bInheritable = false)
		{
			_ASSERTE(!isValid());
			return ((m_h = ::OpenEvent(dwAccess, bInheritable, pszName)) != NULL);
		}

		bool set()
		{	
			_ASSERTE(isValid());
			return SetEvent(m_h) == TRUE;
		}
		bool reset()
		{	
			_ASSERTE(isValid());
			return ResetEvent(m_h) == TRUE;
		}
	};
}

